import { ActionState, LogExtra } from "./LogManager";


/**
 * 生成日志消息
 * 格式为  [FileName/functionName] [ActionName/ActionState] msg
 * eg:
 *
 *
 * @param fileName
 * @param functionName
 * @param action
 * @param status
 * @param detail
 * @param extraModuleName
 * @returns
 */
export function generateMsg2(detail: string = "", logExtra?: LogExtra) {
  let msg = "";
  if (logExtra?.c && logExtra.c.tags) {
    if (logExtra?.tags) {
      logExtra.tags.push(...logExtra.c.tags)
    } else {
      logExtra.tags = logExtra.c.tags;
    }
  }
  if (logExtra && logExtra.tags?.length) {
    msg += `[${logExtra.tags.join("")}]`
  }
  if (logExtra?.fileName) {
    msg += `[${logExtra.fileName}/${logExtra.funName}]`;
  }
  //action都没有就不要state了.
  if (logExtra?.action) {
    msg += `[${logExtra.action}/${logExtra.state}]`
  }
  if (detail) {
    if (logExtra?.c?.caller) {
      msg += ` caller:${logExtra.c.caller}`
    }
    msg += ` ${detail}`;
  }
  return msg;
}


export function generateMsg(fileName: string, funName: string, action: string, state: ActionState | string,
  detail: string = "", ...extraModuleName: string[]) {
  let msg = "";
  if (extraModuleName && extraModuleName.length) {
    msg += `[${extraModuleName.join("")}]`
  }
  if (fileName) {
    msg += `[${fileName}/${funName}]`;
  }
  //action都没有就不要state了.
  if (action) {
    msg += `[${action}/${state}]`
  }
  if (detail) {
    msg += ` [${detail}]`;
  }
  return msg;
}


export function getObjInfo(obj: any, confuseAccountKey?: string): string {
  if (obj === undefined) {
    return "undefined"
  }
  if (obj === null) {
    return "null"
  }
  if (typeof obj === "string") {
    return obj;
  }
  return JSON.stringify(obj);
}